package com.project.dto;

import lombok.Data;

import java.util.List;

/**
 * 返回对象
 * @param <T>
 */
@Data
public class R<T> {
    private String code;
    private String message;
    private T data;
    private List<T> dataList;

    public static <T> R<T> success() {
        R<T> r = new R<>();
        r.setCode("0000");
        r.setMessage("success");
        return r;
    }
    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.setCode("0000");
        r.setMessage("success");
        r.setData(data);
        return r;
    }


    public static <T> R<T> success(List<T> dataList) {
        R<T> r = new R<>();
        r.setCode("0000");
        r.setMessage("success");
        r.setDataList(dataList);
        return r;
    }

    public static <T> R<T> fail(String message) {
        R<T> r = new R<>();
        r.setCode("9999");
        r.setMessage(message);
        return r;
    }

    public static <T> R<T> fail(String code,String message) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }
}
